<template>
  <div class="navigation">
    <!-- Logo 图片 -->
    <img :src="logoUrl" alt="宠物之家 Logo" class="logo" />
    
    <!-- 导航链接容器 -->
    <div class="nav-links">
      <router-link 
        to="/home" 
        class="nav-link"
        :class="{ 'active': $route.path === '/home' }"
      >首页</router-link>
      
      <router-link 
        to="/pet-adoption" 
        class="nav-link"
        :class="{ 'active': $route.path === '/pet-adoption' }"
      >宠物领养</router-link>
      
      <router-link 
        to="/Pet-AdoptionRegistration" 
        class="nav-link"
        :class="{ 'active': $route.path === '/Pet-AdoptionRegistration' }"
      >领养进度</router-link>
      
      <router-link 
        to="/pet-lost" 
        class="nav-link"
        :class="{ 'active': $route.path === '/pet-lost' }"
      >宠物挂失</router-link>
            
      <router-link 
        to="/pet-products" 
        class="nav-link"
        :class="{ 'active': $route.path === '/pet-products' }"
      >宠物用品</router-link>
      
      <router-link 
        to="/shopping-cart" 
        class="cart-link" 
        @mouseover="hoverPreviewVisible = true" 
        @mouseleave="hoverPreviewVisible = false"
        :class="{ 'active': $route.path === '/shopping-cart' }"
      >
        购物车
        <span class="cart-badge" :class="{ 'animate': animateBadge, 'hidden': cartCount === 0 }">
          {{ cartCount }}
        </span>
      </router-link>
      
      <router-link 
        to="/forum" 
        class="nav-link"
        :class="{ 'active': $route.path === '/forum' }"
      >论坛信息</router-link>

      <router-link 
        to="/profile" 
        class="nav-link"
        :class="{ 'active': $route.path === '/profile' }"
      >个人中心</router-link>

      <router-link 
  to="/gitee" 
  class="nav-link"
  :class="{ 'active': $route.path === '/gitee' }"
>Gitee</router-link>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();
const logoUrl = new URL('/src/assets/images/logo.jpg', import.meta.url).href;
const cartCount = ref(0);
const animateBadge = ref(false);
const hoverPreviewVisible = ref(false);

// 模拟添加商品到购物车
const addToCart = (item) => {
  cartCount.value += item.quantity;
  triggerBadgeAnimation();
};

const triggerBadgeAnimation = () => {
  animateBadge.value = true;
  setTimeout(() => {
    animateBadge.value = false;
  }, 300);
};
</script>

<style scoped>
/* 导航栏整体样式 */
.navigation {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  background-color: #f9f3e6;
  border-radius: 30px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  font-family: 'Poppins', sans-serif;
  max-width: 100%;
  box-sizing: border-box;
  border: 2px solid #d4af37;
}

/* Logo 样式 */
.logo {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 15px;
  border: 3px solid #f4a261;
}

/* 导航链接容器 */
.nav-links {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 四列布局 */
  gap: 10px;
  width: 100%;
}

/* 导航链接基础样式 */
.nav-link, .cart-link {
  color: #4a4a4a;
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 500;
  padding: 8px 5px;
  text-align: center;
  transition: all 0.3s ease;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 悬停效果 */
.nav-link:hover, .cart-link:hover {
  color: #e76f51;
  background-color: rgba(231, 111, 81, 0.1);
}

/* 当前页面激活状态 */
.nav-link.active, .cart-link.active {
  color: #e76f51;
  font-weight: 600;
  background-color: rgba(231, 111, 81, 0.1);
}

/* 购物车徽章样式 */
.cart-badge {
  background-color: #e74c3c;
  color: #ffffff;
  border-radius: 50%;
  padding: 2px 6px;
  font-size: 0.8rem;
  margin-left: 5px;
  transition: transform 0.3s ease;
}

.cart-badge.animate {
  transform: scale(1.2);
}

.cart-badge.hidden {
  display: none;
}

/* 响应式设计 - 更小的屏幕调整为两列 */
@media (max-width: 480px) {
  .nav-links {
    grid-template-columns: repeat(2, 1fr); /* 两列布局 */
  }
  
  .nav-link, .cart-link {
    font-size: 1.1rem;
    padding: 6px 3px;
  }
}

/* 中等屏幕 - 三列布局 */
@media (min-width: 481px) and (max-width: 768px) {
  .nav-links {
    grid-template-columns: repeat(3, 1fr); /* 三列布局 */
  }
  
  .nav-link, .cart-link {
    font-size: 1.2rem;
    padding: 8px 5px;
  }
}

/* 大屏幕 - 恢复水平布局 */
@media (min-width: 769px) {
  .navigation {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 15px 10px;
  }
  
  .logo {
    margin-bottom: 0;
    margin-right: 20px;
  }
  
  .nav-links {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
  }
  
  .nav-link, .cart-link {
    font-size: 1.4rem;
    padding: 5px 10px;
  }
  
  .nav-link.active::after, .cart-link.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
  }
  
  .nav-link:hover, .cart-link:hover {
    transform: scale(1.05);
    background-color: transparent;
  }
}
</style>